﻿@model ReturnRequestListModel
@using Telerik.Web.Mvc.UI
@{  
    ViewBag.Title = T("Admin.ReturnRequests").Text;
}

<div class="section-header">
    <div class="title">
        <i class="fa fa-truck"></i>
        @T("Admin.ReturnRequests")
    </div>
    <div class="options">
    </div>
</div>

<div class="row mt-3 grid-filter">
	<div class="col-sm-6 col-lg-4 col-xl-3 form-group">
		@Html.SmartLabelFor(model => model.SearchId)
		@Html.TextBoxFor(model => Model.SearchId, new { @class = "form-control" })
	</div>
	@if (Model.AvailableStores.Count > 1)
	{
		<div class="col-sm-6 col-lg-4 col-xl-3 form-group">
			@Html.SmartLabelFor(model => model.SearchStoreId)
			@Html.DropDownListFor(model => model.SearchStoreId, Model.AvailableStores, T("Admin.Common.All"), new { @class = "form-control" })
		</div>
	}
	<div class="col-sm-6 col-lg-4 col-xl-3 form-group">
		@Html.SmartLabelFor(model => model.SearchReturnRequestStatusId)
		@Html.DropDownListFor(model => model.SearchReturnRequestStatusId, Model.AvailableReturnRequestStatus, T("Admin.Common.All"))
	</div>
	<div class="col-sm-6 col-lg-4 col-xl-3 form-group">
		@Html.SmartLabel(string.Empty, string.Empty)
		<button type="submit" id="btnSearch" value="btnSearch" class="btn btn-secondary btn-block">
			<span>@T("Admin.Common.Search")</span>
		</button>
	</div>
</div>

<div>
	@(Html.Telerik().Grid<ReturnRequestModel>()
			.Name("returnrequests-grid")
			.Columns(columns =>
			{
				columns.Bound(x => x.Id)
					.Centered()
					.Width(100);
				columns.Bound(x => x.ProductName)
					.Template(x => @Html.LabeledProductName(x.ProductId, x.ProductName, x.ProductTypeName, x.ProductTypeLabelHint))
					.ClientTemplate(@Html.LabeledProductName("ProductId", "ProductName"));
				columns.Bound(x => x.Quantity)
					.Width(100)
					.Centered();
				columns.Bound(x => x.CustomerId)
					.Template(x => Html.ActionLink(T("Admin.Common.View").Text, "Edit", "Customer", new { id = x.CustomerId }, new { }))
					.ClientTemplate("<a href=\"" + @Url.Content("~/Admin/Customer/Edit/") + "<#= CustomerId #>\"><#= CustomerFullName #></a>");
				columns.Bound(x => x.OrderId)
					.Width(100)
					.Centered()
					.Template(x => Html.ActionLink(T("Admin.Common.View").Text, "Edit", "Order", new { id = x.OrderId }, new { }))
					.ClientTemplate("<a href=\"" + @Url.Content("~/Admin/Order/Edit/") + "<#= OrderId #>\"><#= OrderId #></a>");
				columns.Bound(x => x.ReturnRequestStatusStr)
					.Width(180);
				columns.Bound(x => x.CreatedOn)
					.Width(180);
				columns.Bound(x => x.StoreName)
					.Hidden(Model.AvailableStores.Count <= 1);
				columns.Bound(x => x.Id)
					.Centered()
					.Template(x => Html.ActionLink(T("Admin.Common.Edit").Text, "Edit", new { id = x.Id }, new { @class = "t-button" }))
					.ClientTemplate("<a href=\"Edit/<#= Id #>\" class=\"t-button\">" + T("Admin.Common.Edit").Text + "</a>")
					.Title(String.Empty)
					.HtmlAttributes(new { align = "right", @class = "omega" });
			})
			.Pageable(settings => settings.PageSize(Model.GridPageSize).Position(GridPagerPosition.Both))
			.DataBinding(dataBinding => dataBinding.Ajax().Select("List", "ReturnRequest"))
			.ClientEvents(events => events.OnDataBinding("returnRequestGrid_onDataBinding"))
			.PreserveGridState()
			.EnableCustomBinding(true))
</div>

<script type="text/javascript">
    $(document).ready(function () {

		$('#btnSearch').click(function () {
        	var grid = $('#returnrequests-grid').data('tGrid');
            grid.currentPage = 1;
            grid.ajaxRequest();
            return false;
        });
    });

    function returnRequestGrid_onDataBinding(e) {
        var searchModel = {
        	SearchId: $('#@Html.FieldIdFor(model => model.SearchId)').val(),
        	SearchStoreId: $('#@Html.FieldIdFor(model => model.SearchStoreId)').val(),
        	SearchReturnRequestStatusId: $('#@Html.FieldIdFor(model => model.SearchReturnRequestStatusId)').val()
        };
        e.data = searchModel;
    }
</script>
